package com.awei.study.design.structure.bridge;

/**
 * @Author liweilong
 * @Date 2024/8/8 12:47
 * 桥接模式
 */
public class bridge {

    public interface VideoFile {
        void decode(String name);
    }

    public static class MkvFile implements VideoFile {

        @Override
        public void decode(String name) {
            System.out.println("播放Mkv类型视频：" + name);
        }
    }

    public static class AViFile implements VideoFile {

        @Override
        public void decode(String name) {
            System.out.println("播放Avi类型视频：" + name);
        }
    }

    public static abstract class OperateSystem {
        protected VideoFile videoFile;

        public OperateSystem(VideoFile videoFile) {
            this.videoFile = videoFile;
        }

        public VideoFile getVideoFile() {
            return videoFile;
        }

        public void setVideoFile(VideoFile videoFile) {
            this.videoFile = videoFile;
        }

        public abstract void display(String fileName);
    }

    public static class Windows extends OperateSystem {

        public Windows(VideoFile videoFile) {
            super(videoFile);
        }

        @Override
        public void display(String fileName) {
            videoFile.decode(fileName);
        }
    }

    public static class Mac extends OperateSystem {

        public Mac(VideoFile videoFile) {
            super(videoFile);
        }

        @Override
        public void display(String fileName) {
            videoFile.decode(fileName);
        }
    }

    public static void main(String[] args) {
        VideoFile aviFile = new AViFile();
        VideoFile mkvFile = new MkvFile();

        OperateSystem windows;
        OperateSystem mac;
        windows = new Windows(aviFile);
        mac = new Mac(aviFile);
        windows.display("神雕侠女");
        mac.display("仙丹超人");
        windows = new Windows(mkvFile);
        mac = new Mac(mkvFile);
        windows.display("神雕侠女");
        mac.display("仙丹超人");
    }
}
